structure VectorExtra = struct
    fun sum vec =
        Vector.foldl (fn (elem, acc) => elem + acc)
                     0
                     vec;

    fun filter proc vec =
        let
            val len = Vector.length vec;
            fun iter (ind, acc) =
                if ind < len
                then
                    let
                        val current = Vector.sub(vec, ind);
                    in
                        if proc current
                        then iter (ind + 1, current :: acc)
                        else iter (ind + 1, acc)
                    end
                else
                    rev acc
        in
            iter (0, [])
        end;

    fun all_in_list vec lst =
        Vector.foldl (fn (elem, acc) =>
                         acc andalso (List.exists (fn lst_elem => lst_elem = elem)
                                                  lst))
                     true
                     vec;
end
